﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using KTX.Public;

namespace KTX.Data
{
    class VaitroData : BaseDAL, IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("select * from vaitro");
        }

        public DataTable Select(string _tenvt)
        {
            string sql = @"Select * From tb_Vaitro Where Ten = '{0}' ";
            sql = string.Format(sql, _tenvt);
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            throw new NotImplementedException();
        }

        public bool Delete(long id)
        {
            var sql = "sp_Delete_Vaitro {0}";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (VaitroPublic)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Vaitro N'{0}', N'{1}' ";
            sql = string.Format(sql, o.Ten, o.Mota);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (VaitroPublic)obj;
            var sql = "set dateformat dmy; execute sp_Update_Vaitro '{0}', N'{1}', N'{2}' ";
            sql = string.Format(sql, o.Id, o.Ten, o.Mota);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            var sql = @"select * from Vaitro where Ten like N'%{0}%' ";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }
    }
}
